/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component, Fragment} from 'react';
import {
  Form,
  Button,
  Badge,
  Radio,
  Tooltip,
  DatePicker,
  Descriptions,
  Tag,
  Icon,
  Switch,
  message,
  Modal,
  Drawer, Carousel, Input,Tabs,Select,TimePicker
} from 'antd';
import {connect} from 'dva';
import forEach from 'lodash/forEach';
import request from '@/utils/request';
import {
  calc,
  formatTime,
  padWithZeros,
  isValidIPv4,
  renderSignalIntensity,
  afterCloseModal
} from '@/utils/utils';
const { TextArea } = Input;
import moment from 'moment';
const { Option } = Select;
const {confirm} = Modal;
const {TabPane}=Tabs
const ButtonGroup = Button.Group;
const FormItem = Form.Item;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.permissions = JSON.parse(sessionStorage.getItem('permissions'));
    this.state = {
      detail: {
        concentrator_info:{},
        latest_data:[],
        config:{}
      },
      searchParams:{
        date:moment().subtract(1, "day").format("YYYY-MM-DD"),
        page: 1,
        per_page: 50,
      },
      meta: {total: 0, per_page: 50,current_page:1},
      editRecord: {},
      data:[],
      step:1,
      type:'',
      sendHexLogs:[]

    };
  }

  componentDidMount() {
    // console.log('this', this.props.editRecord);
    const that = this;
  }

  clickItem(type) {
    console.log(type)
    this.setState({
      type:type,
      step:2,

    })

  }
  getName () {
    let n1 = this.props.editRecord.number.substr(0, 2)
    let n2 = this.props.editRecord.number.substr(2, 2)
    let n3 = this.props.editRecord.number.substr(4, 2)
    let n4 = this.props.editRecord.number.substr(6, 2)
    return `${n4} ${n3} ${n2} ${n1}`
  }
  getTime () {
    let date = formatTime(new Date())
    let b1 = date.substr(0, 2)
    let b2 = date.substr(2, 2)
    let b3 = date.substr(5, 2)
    let b4 = date.substr(8, 2)
    let b5 = date.substr(11, 2)
    let b6 = date.substr(14, 2)
    let b7 = date.substr(17, 2)
    return `${b7} ${b6} ${b5} ${b4} ${b3} ${b2} ${b1}`
  }
  handleSend82=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;

      let str = `0E ${this.getName()} 00 82 ${fieldsValue.postIndex} ${fieldsValue.valveIndex} 00 ${this.getTime()} ${this.getTime()} 00 00 00 00`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
  handleSend83=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let input2 = padWithZeros(fieldsValue.input2.toString(16), 4, '0')
      let str = `0E ${this.getName()} 00 83 ${input2.substr(2, 2)} ${input2.substr(0, 2)} ${moment(fieldsValue.timeArr).format('ss')} ${moment(fieldsValue.timeArr).format('mm')} ${moment(fieldsValue.timeArr).format('HH')} 14 00 00`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
  handleSendE0=()=>{

    let str = `0E ${this.getName()} 00 E0`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
 }
  handleSendE5=()=>{

    let str = `0E ${this.getName()} 00 E5`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
 }
  handleSendE7=()=>{

    let str = `0E ${this.getName()} 00 E7`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
 }
  handleSendE2=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let str = `0E ${this.getName()} 00 E2 ${moment(fieldsValue.timeArr).format('HH')} ${moment(fieldsValue.timeArr).format('mm')} ${moment(fieldsValue.timeArr).format('HH')} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(8, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(5, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(2, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(0, 2)} ${input1}`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
  handleSendE3=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;

      let str = `0E ${this.getName()} 00 E3 ${fieldsValue.postIndex} ${fieldsValue.postIndex2} `

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
  handleSendE8=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let input1 = padWithZeros(fieldsValue.input1.toString(16), 2, '0')
      let str = `0E ${this.getName()} 00 E8 ${fieldsValue.postIndex} ${moment(fieldsValue.timeArr).format('mm')} ${moment(fieldsValue.timeArr).format('HH')} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(8, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(5, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(2, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(0, 2)} ${input1}`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
  handleSendE9=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let input1 = padWithZeros(fieldsValue.input1.toString(16), 2, '0')
      let str = `0E ${this.getName()} 00 E9 ${fieldsValue.postIndex} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(8, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(5, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(2, 2)} ${moment(fieldsValue.dateIndex).format('YYYY-MM-DD').substr(0, 2)} ${input1}`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
  handleSendEA=()=>{

    let str = `0E ${this.getName()} 00 EA`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSendEB=()=>{

    let str = `0E ${this.getName()} 00 EB`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSendEF=()=>{

    let str = `0E ${this.getName()} 00 EF`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSendEC=()=>{

    let str = `0E ${this.getName()} 00 EC`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSendED=()=>{

    let str = `0E ${this.getName()} 00 ED`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSendEE=()=>{

    let str = `0E ${this.getName()} 00 EE`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSendE4=()=>{

    let str = `0E ${this.getName()} 00 E4`
    let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
    console.log('sendHex', sendHex)

    this.writeBLECharacteristicValue(sendHex)
  }
  handleSend84=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      if (!isValidIPv4(fieldsValue.input1)) {
        message.error(`IP地址格式错误`);
        return
      }
      let i1 = Number(fieldsValue.input1.split(".")[0]).toString(16)
      let i2 = Number(fieldsValue.input1.split(".")[1]).toString(16)
      let i3 = Number(fieldsValue.input1.split(".")[2]).toString(16)
      let i4 = Number(fieldsValue.input1.split(".")[3]).toString(16)

      let input2 = padWithZeros(Number(fieldsValue.input2).toString(16), 4);

      let str = `0E ${this.getName()} 00 84 ${fixedZero(i4)} ${fixedZero(i3)} ${fixedZero(i2)} ${fixedZero(i1)} ${input2.substr(0, 2)} ${input2.substr(2, 2)}`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)

      this.writeBLECharacteristicValue(sendHex)
    });

  }
  handleSend85=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let input1 = padWithZeros(parseInt(Number(fieldsValue.input1) * 1000), 8, '0')
      let str = `0E ${this.getName()} 00 85 ${fieldsValue.postIndex} ${input1.substr(6, 2)} ${input1.substr(4, 2)} ${input1.substr(2, 2)} ${input1.substr(0, 2)} 2C`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)

      this.writeBLECharacteristicValue(sendHex)
    });

  }
  handleSendE6=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;

      let str = `9E ${this.getName()} 00 E6 ${fieldsValue.postIndex}`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)
      this.writeBLECharacteristicValue(sendHex)
    });
  }
   decToHex=(number)=>{
    return (parseInt(number,10)>>>0).toString(16).toLocaleUpperCase();
  }
  handleSend86=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let str ='';
      let input1=''
      let input2 = padWithZeros(Number(fieldsValue.input2).toString(16), 4, '0')
      if(Number(fieldsValue.input1)>=0){
        console.log('大于0')
        input1 = padWithZeros(parseInt(Number(fieldsValue.input1) * 1000).toString(16), 8, '0')
        console.log('input1',input1)
        str = `0E ${this.getName()} 00 86 ${fieldsValue.postIndex} ${input1.substr(6, 2)} ${input1.substr(4, 2)} ${input1.substr(2, 2)} ${input1.substr(0, 2)} ${input2.substr(2, 2)} ${input2.substr(0, 2)} 00 00`

      }else if(Number(fieldsValue.input1)<0){
        console.log('用水量',Number(fieldsValue.input1))
        console.log('小于0')
        input1 = this.decToHex(Number(fieldsValue.input1) * 1000)
        console.log('input1',input1)
        str = `0E ${this.getName()} 00 86 ${fieldsValue.postIndex} ${input1.substr(6, 2)} ${input1.substr(4, 2)} ${input1.substr(2, 2)} ${input1.substr(0, 2)} ${input2.substr(2, 2)} ${input2.substr(0, 2)} 00 00`

      }
     let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)

      this.writeBLECharacteristicValue(sendHex)
    });

  }
  handleSendF0=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      let str = `0E ${this.getName()} 00 F0 ${fieldsValue.postIndex} ${fieldsValue.eventIndex} ${padWithZeros(Number(fieldsValue.input1).toString(16), 2, '0')}`

      let sendHex = '68 ' + str + ' ' + calc(str) + ' 16'
      console.log('sendHex', sendHex)

      this.writeBLECharacteristicValue(sendHex)
    });

  }
  handleSend00=()=>{
    const { form } = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;

      let sendHex = fieldsValue.input1
      console.log('sendHex', sendHex)

      this.writeBLECharacteristicValue(sendHex)
    });

  }
  removeSpaces(str) {
    return str.replace(/\s/g, "");
  }
  writeBLECharacteristicValue=(sendHex)=>{
    this.state.sendHexLogs.unshift(`${moment().format('YYYY-MM-DD HH:mm:ss')} : `+sendHex)
    this.setState({
      sendHexLogs: this.state.sendHexLogs
    })
    const that = this;
    request(`/commands`, {
      method: 'POST',
      data: {
        number:this.props.editRecord.number,
        command:this.removeSpaces(sendHex)
      }
    }).then((response) => {
      if (response.status === 200) {
        message.success('指令发送成功')
        this.props.handleSearch({  ...this.props.searchCondition})
      }

    });
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };
    const formItemLayoutWithLabel2 = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 9},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 13},
      }
    };
    const that=this
    const {
      form: { getFieldDecorator },
    } = this.props;
    return (
      <div>
        {
          this.state.step===1&&
          <div className="weui-grids">
            <div data-type="阀控" onClick={()=>{this.clickItem('阀控')}}  hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 阀控</div>
            </div>
            <div data-type="请求上线" onClick={()=>{this.clickItem('请求上线')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 请求上线</div>
            </div>
            <div data-type="读电压电流" onClick={()=>{this.clickItem('读电压电流')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 读电压电流</div>
            </div>

            <div data-type="设置上报参数" onClick={()=>{this.clickItem('设置上报参数')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 设置上报参数</div>
            </div>
            <div data-type="读上报情况" onClick={()=>{this.clickItem('读上报情况')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 读上报情况</div>
            </div>
            <div data-type="读地址" onClick={()=>{this.clickItem('读地址')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 读地址</div>
            </div>
            <div data-type="设置表底数" onClick={()=>{this.clickItem('设置表底数')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label"> 设置表底数</div>
            </div>
            <div data-type="清零" onClick={()=>{this.clickItem('清零')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">清零</div>
            </div>
            <div data-type="设置服务器地址" onClick={()=>{this.clickItem('设置服务器地址')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">设置服务器地址</div>
            </div>
            <div data-type="设置出厂" onClick={()=>{this.clickItem('设置出厂')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">设置出厂</div>
            </div>
            <div data-type="取消出厂" onClick={()=>{this.clickItem('取消出厂')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">取消出厂</div>
            </div>
            <div data-type="读点冻结" onClick={()=>{this.clickItem('读点冻结')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">读点冻结</div>
            </div>
            <div data-type="读日冻结" onClick={()=>{this.clickItem('读日冻结')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">读日冻结</div>
            </div>
            <div data-type="设置采集器地址" onClick={()=>{this.clickItem('设置采集器地址')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">设置采集器地址</div>
            </div>
            <div data-type="校时" onClick={()=>{this.clickItem('校时')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">校时</div>
            </div>
            <div data-type="请求自测试" onClick={()=>{this.clickItem('请求自测试')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">请求自测试</div>
            </div>
            <div data-type="读自测结果" onClick={()=>{this.clickItem('读自测结果')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">读自测结果</div>
            </div>
            <div data-type="调整端口号" onClick={()=>{this.clickItem('调整端口号')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">调整端口号</div>
            </div>
            <div data-type="读参数" onClick={()=>{this.clickItem('读参数')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">读参数</div>
            </div>
            <div data-type="读表数据" onClick={()=>{this.clickItem('读表数据')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">读表数据</div>
            </div>
            <div data-type="设置表参数" onClick={()=>{this.clickItem('设置表参数')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">设置表参数</div>
            </div>
            <div data-type="读事件记录" onClick={()=>{this.clickItem('读事件记录')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">读事件记录</div>
            </div>
            <div data-type="充值" onClick={()=>{this.clickItem('充值')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">充值</div>
            </div>
            <div data-type="自定义" onClick={()=>{this.clickItem('自定义')}} hover-class="grid-item-active" className="weui-grid grid-item">
              <div className="weui-grid__label">自定义</div>
            </div>
          </div>
        }
        {
          this.state.step===2&&
          <div>
            <div style={{marginBottom:'10px',padding:'5px',borderBottom:'1px solid #ccc',fontWeight:'bold'}}>
              <Icon type="rollback"  style={{fontSize:'18px',cursor:'pointer'}} onClick={()=>{
                this.setState({
                  step:1,
                  type:''
                })
              }}/>
              <span style={{marginLeft:'5px',fontSize:'18px'}}>{this.state.type}</span>
            </div>
            {
              this.state.type==='阀控'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="控制选择">
                  {getFieldDecorator('valveIndex', {
                    initialValue: '55',
                    rules: [{ required: true, message: '控制选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="55">开阀</Option>
                    <Option value="AA">关阀</Option>
                  </Select>)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSend82}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '请求上线' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE0}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '读电压电流' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE4}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '读地址' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE5}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '读上报情况' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE7}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '设置上报参数' &&
              <Form>
                <FormItem   {...formItemLayoutWithLabel2} label="上报起始时间">
                  {getFieldDecorator('timeArr', {
                    initialValue: moment(),
                    rules: [{ required: true, message: '上报起始时间' }],
                  })(<TimePicker style={{width:'100%'}}/>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="单采集器上报耗时(秒)">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '单采集器上报耗时(秒)' }],
                  })(<Input />)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="采集器分组大小(只)">
                  {getFieldDecorator('input2', {
                    initialValue: '',
                    rules: [{ required: true, message: '采集器分组大小(只)' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 13, offset: 9 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSend83}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type==='设置表底数'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="表底数(m³)">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '表底数(m³)' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSend85}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type==='清零'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE6}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }

            {
              this.state.type === '设置服务器地址' &&
              <Form>
                <FormItem   {...formItemLayoutWithLabel2} label="IP">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: 'IP' }],
                  })(<Input />)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="端口">
                  {getFieldDecorator('input2', {
                    initialValue: '',
                    rules: [{ required: true, message: '端口' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 13, offset: 9 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSend84}>
                    确定
                  </Button>
                </FormItem>
                <FormItem  wrapperCol={{ span: 13, offset: 9 }}>
                  若新设置的服务器地址后，下次上报不成功，采集器会恢复设置前的地址。
                </FormItem>
              </Form>
            }
            {
              this.state.type === '设置出厂' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendEC}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '取消出厂' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendED}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '请求自测试' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendEE}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type==='读点冻结'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="冻结起始日期">
                  {getFieldDecorator('dateIndex', {
                    initialValue: moment(),
                    rules: [{ required: true, message: '冻结起始日期' }],
                  })(<TimePicker style={{width:'100%'}}/>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="冻结起始时间">
                  {getFieldDecorator('timeArr', {
                    initialValue: moment(),
                    rules: [{ required: true, message: '冻结起始时间' }],
                  })(<TimePicker style={{width:'100%'}}/>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="读取条数">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '读取条数' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE8}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type==='读日冻结'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="冻结起始日期">
                  {getFieldDecorator('dateIndex', {
                    initialValue: moment(),
                    rules: [{ required: true, message: '冻结起始日期' }],
                  })(<TimePicker style={{width:'100%'}}/>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="读取条数">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '读取条数' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE9}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type==='校时'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="冻结起始日期">
                  {getFieldDecorator('dateIndex', {
                    initialValue: moment(),
                    rules: [{ required: true, message: '冻结起始日期' }],
                  })(<TimePicker style={{width:'100%'}}/>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel2} label="冻结起始时间">
                  {getFieldDecorator('timeArr', {
                    initialValue: moment(),
                    rules: [{ required: true, message: '冻结起始时间' }],
                  })(<TimePicker style={{width:'100%'}}/>)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE2}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }

            {
              this.state.type==='调整端口号'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="原端子号">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '原端子号' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="新端子号">
                  {getFieldDecorator('postIndex2', {
                    initialValue: '01',
                    rules: [{ required: true, message: '新端子号' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendE3}>
                    确定
                  </Button>
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  将原端子号迁移到新端子号上，该操作会导致新端子号上的数据被覆盖，请谨慎操作。
                </FormItem>
              </Form>
            }
            {
              this.state.type === '读参数' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendEA}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '读表数据' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendEB}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type === '读自测结果' &&
              <Form>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendEF}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }

            {
              this.state.type==='读事件记录'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="事件类型">
                  {getFieldDecorator('eventIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '事件类型' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">充值记录</Option>
                    <Option value="02">阀控记录</Option>
                    <Option value="03">设底度记录</Option>
                    <Option value="04">清零记录</Option>
                    <Option value="05">端子变更记录</Option>
                    <Option value="06">掉电记录</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="事件序号">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '事件序号' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSendF0}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }

            {
              this.state.type==='充值'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="端子选择">
                  {getFieldDecorator('postIndex', {
                    initialValue: '01',
                    rules: [{ required: true, message: '端子选择' }],
                  })(<Select  style={{width:'100%'}}>
                    <Option value="01">01</Option>
                    <Option value="02">02</Option>
                    <Option value="03">03</Option>
                    <Option value="04">04</Option>
                    <Option value="05">05</Option>
                    <Option value="06">06</Option>
                    <Option value="07">07</Option>
                    <Option value="08">08</Option>
                  </Select>)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="充值水量(m³)">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '充值水量(m³)' }],
                  })(<Input />)}
                </FormItem>
                <FormItem   {...formItemLayoutWithLabel} label="充值次数">
                  {getFieldDecorator('input2', {
                    initialValue: '',
                    rules: [{ required: true, message: '充值次数' }],
                  })(<Input />)}
                </FormItem>
                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSend86}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.type==='自定义'&&
              <Form>
                <FormItem   {...formItemLayoutWithLabel} label="指令">
                  {getFieldDecorator('input1', {
                    initialValue: '',
                    rules: [{ required: true, message: '指令' }],
                  })(<TextArea rows={4} />)}
                </FormItem>

                <FormItem  wrapperCol={{ span: 15, offset: 7 }}>
                  <Button block={true} type={'primary'} onClick={this.handleSend00}>
                    确定
                  </Button>
                </FormItem>
              </Form>
            }
            {
              this.state.sendHexLogs.map((item,index)=>{
                return <div style={{marginTop:'10px'}} key={index}>
                  <p>{item}</p>
                </div>
              })
            }
          </div>
        }

      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);
